package com.zbkj.service.service.project.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.common.model.project.ProjectReport;
import com.zbkj.common.request.project.AdminReportRequest;
import com.zbkj.service.dao.project.ProjectReportMapper;
import com.zbkj.service.service.project.ProjectReportService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Objects;

/**
 * <p>
 * 项目报告估算结果表 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-07-09
 */
@Service
public class ProjectReportServiceImpl extends ServiceImpl<ProjectReportMapper, ProjectReport> implements ProjectReportService {


    @Override
    public ProjectReport getByProjectId(Long projectId) {
        if(Objects.isNull(projectId)) {
            return null;
        }
        LambdaQueryWrapper<ProjectReport> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(ProjectReport::getDeleteFlag, 0)
                .eq(ProjectReport::getProjectId, projectId);
        return this.getOne(queryWrapper,false);
    }

    @Override
    public void saveOrUpdateReport(AdminReportRequest reportRequest) {
        ProjectReport report = new ProjectReport();
        BeanUtils.copyProperties(reportRequest, report);
        ProjectReport reportDb = getByProjectId(report.getProjectId());
        if(Objects.isNull(reportDb)) {
            this.save(report);
        } else {
            report.setId(reportDb.getId());
            this.updateById(report);
        }
    }
}
